package com.lujuncheng.tankgame;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

/**
 * @author LuJuncheng
 * @version 1.0
 * JFrame启动方法
 */
public class TankGame extends JFrame {

    MyPanel mp=null;
    static Scanner scanner=new Scanner(System.in);

    public static void main(String[] args) {
        new TankGame();
    }

    public TankGame(){
        System.out.println("请输入选择 1:新游戏 2：继续上局");
        String key=scanner.next();
        mp=new MyPanel(key);
        //将mp放入Thread,并启动,用于刷新屏幕
        new Thread(mp).start();
        this.add(mp);//把面板（就是游戏的绘图区域）
        this.setSize(1300,950);
        this.addKeyListener(mp);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        //在JFrame中增加相应关闭窗口的处理
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
//                System.out.println("监听到关闭窗口了");
                Recorder.keepRecord();
                System.exit(0);
            }
        });
    }
}
